Packages Used

In [1]:
import plotly
from plotly.graph_objs import Scatter, Layout
import pandas as pd
import numpy as np
import locale
locale.setlocale(locale.LC_ALL, '')
from plotly.graph_objs import *
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('seaborn-whitegrid')

Set plotly to offline; produce all plots in the notebook

In [2]:
plotly.offline.init_notebook_mode(connected=True)

Import the best conditional model's test set performance

Which does not contain independent variables. THIS IS A NON ROBUST CODE SECTION, IF PREVIOUS NOTEBOOKS ARE UPDATED THIS MANUAL LOADING OF THE BEST MODEL MAY NOT ACTUALLY BE LOADING THE BEST MODEL.

In [3]:
# Import best notebook and narrow that information to only the best model
best_notebooks_test_perf = pd.read_csv("C:\\Users\\Jeremy Diaz\\Documents\\earth-analytics\\tornadoesr\\Complete_Workflow\\19_test_perf.csv")

best_model_perf = best_notebooks_test_perf.loc[best_notebooks_test_perf['model_number'] == 5]
best_model_perf = best_model_perf.reset_index(drop = True)

Import the unprocessed data

To undo the data processing with the same values.

In [4]:
unproc_tor_df = pd.read_csv("C:\\Users\\Jeremy Diaz\\Documents\\earth-analytics\\tornadoesr\\data\\raw\\tor_data_with_derived.csv")

Storing those values.

In [5]:
mean_lat = np.mean(unproc_tor_df['BEGIN_LAT'])
stand_dev_lat = np.std(unproc_tor_df['BEGIN_LAT'])

mean_lon = np.mean(unproc_tor_df['BEGIN_LON'])
stand_dev_lon = np.std(unproc_tor_df['BEGIN_LON'])

mean_log_dam = np.mean(np.log(unproc_tor_df['DAMAGE_PROPERTY'] + 1))
stand_dev_log_dam = np.std(np.log(unproc_tor_df['DAMAGE_PROPERTY'] + 1))

Import the test set

To get location information.

In [6]:
test_set = pd.read_csv("C:\\Users\\Jeremy Diaz\\Documents\\earth-analytics\\tornadoesr\\data\\raw\\tor_test_set_no_zeros.csv")

Undo the processing.

In [7]:
test_set['natural_scale_true'] = np.exp((test_set['DAMAGE_PROPERTY'] * stand_dev_log_dam) + mean_log_dam) - 1

test_set['natural_scale_pred'] = np.exp((best_model_perf['predicted_values'] * stand_dev_log_dam) + mean_log_dam) - 1

test_set['natural_scale_resid'] = test_set['natural_scale_pred'] - test_set['natural_scale_true']

test_set['BEGIN_LAT'] = (test_set['BEGIN_LAT'] * stand_dev_lat) + mean_lat

test_set['BEGIN_LON'] = (test_set['BEGIN_LON'] * stand_dev_lon) + mean_lon

This will tell whether each prediction was an over- or underestimate, get the absolute difference between predicted and true values (in log-10 scale), then apply the corresponding sign for that difference (negative for underestimates and positive for overestimates).

In [8]:
sign_list = []

for i in range(len(test_set)):
    
    if test_set['natural_scale_resid'][i] > 0:
        sign_list.append(1)
        
    else:
        sign_list.append(-1)
    
test_set['natural_resid_sign'] = sign_list

test_set['log_10_abs_resid'] = np.log10(abs(test_set['natural_scale_resid']))

test_set['log_10_resid_direction'] = test_set['natural_resid_sign'] * test_set['log_10_abs_resid']

Getting a clean label for each point.

In [9]:
labels = []

for i in range(len(test_set['natural_scale_resid'])):
    
    intermediate = locale.format("%d", test_set["natural_scale_resid"][i], grouping = True)
    
    intermediate = "$" + intermediate
    
    labels.append(intermediate)

resid_str_list = np.repeat('Residual: ', len(test_set))

true_str_list = np.repeat('<br>True Damage: ', len(test_set))


labels_better = []

for i in range(len(test_set)):
    
    intermediate = locale.format("%d", test_set["natural_scale_true"][i], grouping = True)
    
    intermediate = "$" + intermediate
    
    intermediate = resid_str_list[i] + labels[i] + true_str_list[i] + intermediate
    
    labels_better.append(intermediate)

Import U.S. cities data

In [10]:
cities_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')

cities_df = cities_df[cities_df['pop'] > 100000]

Get some clean, useful labels for each city point

In [11]:
cities_df['pop'] = cities_df.apply(lambda x: "{:,}".format(x['pop']), axis=1)

city_labels = "Name: " + cities_df['name'] + "<br>Population: " + cities_df['pop']

The Test Set Residual Map

This will produce the map, showing where and by how much the best conditional model was wrong. Dark blues imply strong overestimates, while dark reds imply strong underestimates. Lighter coolors indicate where the model did relatively well.

In [12]:
trace1 = {"lon": test_set["BEGIN_LON"],
          "lat":  test_set["BEGIN_LAT"],
          "name": "Residual",
          "text": labels_better,
          "marker": {"color": test_set["log_10_resid_direction"],
                     "colorscale": [[0.0, 'rgb(165,0,38)'],
                                         [0.1111111111111111, 'rgb(215,48,39)'],
                                         [0.2222222222222222, 'rgb(244,109,67)'],
                                         [0.3333333333333333, 'rgb(253,174,97)'],
                                         [0.4444444444444444, 'rgb(254,224,144)'],
                                         [0.5555555555555556, 'rgb(224,243,248)'],
                                         [0.6666666666666666, 'rgb(171,217,233)'],
                                         [0.7777777777777778, 'rgb(116,173,209)'],
                                         [0.8888888888888888, 'rgb(69,117,180)'],
                                         [1.0, 'rgb(49,54,149)']],
                     "size": 5.5,
                     "cmin": test_set['log_10_resid_direction'].min(),
                     "cmax": test_set['log_10_resid_direction'].min(),
                     "colorbar": dict(title = 'Direction and Magnitude<br>of Residual')},
          "type": "scattergeo", 
          "visible": True}

trace2 = {"lon": cities_df["lon"],
          "lat":  cities_df["lat"],
          "name": "City",
          "text": city_labels,
          "marker": {"size": 5,
                     "symbol": "star-open",
                     "color": "black"},
          "type": "scattergeo"}

data = Data([trace1, trace2])

layout = dict(geo = dict(scope = 'north america',
                         showland = True,
                         landcolor = "rgb(255, 255, 255)",
                         subunitcolor = "rgb(0, 0, 0)",
                         countrycolor = "rgb(0, 0, 0)",
                         showlakes = True,
                         showocean = True,
                         lakecolor = "rgb(247, 247, 247)",
                         oceancolor = "rgb(247, 247, 247)",
                         showsubunits = True,
                         showcountries = True,
                         resolution = 50,
                         lonaxis = dict(showgrid = True,
                                        gridwidth = 0.05,
                                        range= [-125.0, -70.0],
                                        dtick = 5),
                         lataxis = dict(showgrid = True,
                                        gridwidth = 0.05,
                                        range= [23.0, 50.0],
                                        dtick = 5)),
              title = 'Map of Test Set Residuals',
              showlegend = False)

fig1 = {'data':data,
       'layout':layout}

plotly.offline.iplot(fig1)

How does the conditional model fail?

Natural scale exploration

In [13]:
plt.scatter(test_set['natural_scale_true'],
            test_set['natural_scale_resid'],
            facecolor = 'k', s = 60)
plt.plot([0, 1e9], [0, -1e9], 'r', lw = 1)
plt.ylabel("Unprocessed Residual", size = 14)
plt.xlabel("True Damage", size = 14)
plt.title("Unprocessed Residuals versus True Damage\n", size = 16);

It appears, when the model underestimates by a large amount it's exclusively because it was a very damaging tornado.

In [14]:
plt.scatter(test_set['natural_scale_pred'],
            test_set['natural_scale_resid'],
            facecolor = 'k', s = 60)
plt.plot([0, 1e9], [0, -1e9], 'r', lw = 1)
plt.ylabel("Unprocessed Residual", size = 14)
plt.xlabel("Prediction", size = 14)
plt.title("Unprocessed Residuals versus Prediction\n", size = 16);

However the model does not exclusively underestimate when it predicts lower-end values.

Processed scale exploration

In [15]:
test_set['residual_of_log_xformed'] = np.log10(test_set['natural_scale_pred']) - np.log10(test_set['natural_scale_true'])
In [16]:
plt.scatter(test_set['DAMAGE_PROPERTY'],
            test_set['residual_of_log_xformed'],
            facecolor = 'k', s = 60)
plt.ylabel("Processed Residual", size = 14)
plt.xlabel("Processed True Damage", size = 14)
plt.title("Processed Residuals versus Processed True Damage\n", size = 16);

While the trend of underestimating at high values remains true in processed-scale data, it is much less severe. The trend here is actually centered on zero, with the model often overpredicting on low values.

This isn't pronounced on the previous plots because the axes are so compressed due to scale.

In [17]:
plt.scatter(best_model_perf['predicted_values'],
            test_set['residual_of_log_xformed'],
            facecolor = 'k', s = 60)
plt.ylabel("Processed Residual", size = 14)
plt.xlabel("Processed Prediction", size = 14)
plt.title("Processed Residuals versus Processed Prediction\n", size = 16);

And it appears that the prediction is not necessarily an over- or underestimate based solely on the value of the prediction, this is a pretty random spread.

The problem displayed by these plots is that the model is optimized using processed data (which is required for decent optimization), and this processed optimization does not optimize well in respect to the extremely damaging events, because it optimizes with respect to magnitude, treating all magnitude differences equally; when in reality, being wrong in the magnitude from 1 to 100 is much less important than being wrong in the magnitude from 10,000 to 1,000,000.

Import the expected values for the grid and cities

In [18]:
grid_exp_val_2018 = pd.read_csv("C:\\Users\\Jeremy Diaz\\Documents\\earth-analytics\\tornadoesr\\Complete_Workflow\\grid_with_expectated_values.csv")

cities_exp_val_2018 = pd.read_csv("C:\\Users\\Jeremy Diaz\\Documents\\earth-analytics\\tornadoesr\\Complete_Workflow\\cities_with_expectated_values.csv")

Making the month variable easier to work with.

Undoing the processing.

In [19]:
grid_exp_val_2018['log_10_dam'] = np.log10(grid_exp_val_2018['DAMAGE_PROPERTY'] + 1)

grid_exp_val_2018['BEGIN_LAT'] = (grid_exp_val_2018['BEGIN_LAT'] * stand_dev_lat) + mean_lat

grid_exp_val_2018['BEGIN_LON'] = (grid_exp_val_2018['BEGIN_LON'] * stand_dev_lon) + mean_lon


cities_exp_val_2018['log_10_dam'] = np.log10(cities_exp_val_2018['DAMAGE_PROPERTY'] + 1)

cities_exp_val_2018['BEGIN_LAT'] = (cities_exp_val_2018['BEGIN_LAT'] * stand_dev_lat) + mean_lat

cities_exp_val_2018['BEGIN_LON'] = (cities_exp_val_2018['BEGIN_LON'] * stand_dev_lon) + mean_lon

Getting the labels.

In [20]:
# For the grid
labels2 = []

for i in range(len(grid_exp_val_2018['DAMAGE_PROPERTY'])):
    
    intermediate = locale.format("%d", grid_exp_val_2018["DAMAGE_PROPERTY"][i], grouping = True)
    
    intermediate = "$" + intermediate
    
    labels2.append(intermediate)
    
grid_exp_val_2018['labels'] = labels2


# For the cities
labels3 = []

for i in range(len(cities_exp_val_2018['DAMAGE_PROPERTY'])):
    
    intermediate = locale.format("%d", cities_exp_val_2018["DAMAGE_PROPERTY"][i], grouping = True)
    
    intermediate = "Name: " + str(cities_exp_val_2018['name'][i]) + "<br>Population: " + str(cities_exp_val_2018['pop'][i]) + "<br>Expected Damage: $" + intermediate
    
    labels3.append(intermediate)
    
cities_exp_val_2018['labels'] = labels3

Separating months so that the map can have a dropdown menu selection.

In [21]:
grid_jan_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 15]
grid_feb_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 46]
grid_mar_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 74]
grid_apr_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 105]
grid_may_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 135]
grid_jun_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 166]
grid_jul_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 196]
grid_aug_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 227]
grid_sep_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 258]
grid_oct_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 288]
grid_nov_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 319]
grid_dec_data = grid_exp_val_2018[grid_exp_val_2018['JULIAN_DAY'] == 349]

cities_jan_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 15]
cities_feb_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 46]
cities_mar_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 74]
cities_apr_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 105]
cities_may_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 135]
cities_jun_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 166]
cities_jul_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 196]
cities_aug_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 227]
cities_sep_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 258]
cities_oct_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 288]
cities_nov_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 319]
cities_dec_data = cities_exp_val_2018[cities_exp_val_2018['JULIAN_DAY'] == 349]

The 2018 expected values map

The map color legend will appear very messy until you select a dropdown button, after which it will be clear. The color legend adjusts slightly with each month due to differences in maximum and minimum expected values in each month.

In [22]:
# Each trace can be thought of as a layer to the map
# trace1-12 are monthly data points
trace1 = {"lon": grid_jan_data["BEGIN_LON"],
          "lat":  grid_jan_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_jan_data["labels"],
          "marker": {"color": grid_jan_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace2 = {"lon": grid_feb_data["BEGIN_LON"],
          "lat":  grid_feb_data["BEGIN_LAT"], 
          "name": "Expected Value",
          "text": grid_feb_data["labels"],
          "marker": {"color": grid_feb_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace3 = {"lon": grid_mar_data["BEGIN_LON"],
          "lat":  grid_mar_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_mar_data["labels"],
          "marker": {"color": grid_mar_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace4 = {"lon": grid_apr_data["BEGIN_LON"],
          "lat":  grid_apr_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_apr_data["labels"],
          "marker": {"color": grid_apr_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace5 = {"lon": grid_may_data["BEGIN_LON"],
          "lat":  grid_may_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_may_data["labels"],
          "marker": {"color": grid_may_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace6 = {"lon": grid_jun_data["BEGIN_LON"],
          "lat":  grid_jun_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_jun_data["labels"],
          "marker": {"color": grid_jun_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace7 = {"lon": grid_jul_data["BEGIN_LON"],
          "lat":  grid_jul_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_jul_data["labels"],
          "marker": {"color": grid_jul_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace8 = {"lon": grid_aug_data["BEGIN_LON"],
          "lat":  grid_aug_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_aug_data["labels"], 
          "marker": {"color": grid_aug_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace9 = {"lon": grid_sep_data["BEGIN_LON"],
          "lat":  grid_sep_data["BEGIN_LAT"],
          "name": "Expected Value",
          "text": grid_sep_data["labels"],
          "marker": {"color": grid_sep_data["log_10_dam"],
                     "colorscale": "Viridis",
                     "size": 2.5,
                     "symbol":"square",
                     "cmin": grid_exp_val_2018['log_10_dam'].min(),
                     "cmax": grid_exp_val_2018['log_10_dam'].min(),
                     "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
          "type": "scattergeo", 
          "visible": True}
trace10 = {"lon": grid_oct_data["BEGIN_LON"],
           "lat":  grid_oct_data["BEGIN_LAT"],
           "name": "Expected Value",
           "text": grid_oct_data["labels"],
           "marker": {"color": grid_oct_data["log_10_dam"],
                      "colorscale": "Viridis",
                      "size": 2.5,
                      "symbol":"square",
                      "cmin": grid_exp_val_2018['log_10_dam'].min(),
                      "cmax": grid_exp_val_2018['log_10_dam'].min(),
                      "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
           "type": "scattergeo", 
           "visible": True}
trace11 = {"lon": grid_nov_data["BEGIN_LON"],
           "lat":  grid_nov_data["BEGIN_LAT"],
           "name": "Expected Value",
           "text": grid_nov_data["labels"],
           "marker": {"color": grid_nov_data["log_10_dam"],
                      "colorscale": "Viridis",
                      "size": 2.5,
                      "symbol":"square",
                      "cmin": grid_exp_val_2018['log_10_dam'].min(),
                      "cmax": grid_exp_val_2018['log_10_dam'].min(),
                      "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
           "type": "scattergeo", 
           "visible": True}
trace12 = {"lon": grid_dec_data["BEGIN_LON"],
           "lat":  grid_dec_data["BEGIN_LAT"],
           "name": "Expected Value",
           "text": grid_dec_data["labels"],
           "marker": {"color": grid_dec_data["log_10_dam"],
                      "colorscale": "Viridis",
                      "size": 2.5,
                      "symbol":"square",
                      "cmin": grid_exp_val_2018['log_10_dam'].min(),
                      "cmax": grid_exp_val_2018['log_10_dam'].min(),
                      "colorbar": dict(title = 'Magnitude of Predicted<br>Property Damage')},
           "type": "scattergeo", 
           "visible": True}


# trace13-24 are identical and are the cities
# They are repeated so that they can be redrawn for each dropdown selection
# Otherwise they become background to the prediction points
# And therefore less visible
trace13 = {"lon": cities_jan_data["BEGIN_LON"],
           "lat": cities_jan_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_jan_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace14 = {"lon": cities_feb_data["BEGIN_LON"],
           "lat": cities_feb_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_feb_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace15 = {"lon": cities_mar_data["BEGIN_LON"],
           "lat": cities_mar_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_mar_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace16 = {"lon": cities_apr_data["BEGIN_LON"],
           "lat": cities_apr_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_apr_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace17 = {"lon": cities_may_data["BEGIN_LON"],
           "lat": cities_may_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_may_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace18 = {"lon": cities_jun_data["BEGIN_LON"],
           "lat": cities_jun_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_jun_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace19 = {"lon": cities_jul_data["BEGIN_LON"],
           "lat": cities_jul_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_jul_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace20 = {"lon": cities_aug_data["BEGIN_LON"],
           "lat": cities_aug_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_aug_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace21 = {"lon": cities_sep_data["BEGIN_LON"],
           "lat": cities_sep_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_sep_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace22 = {"lon": cities_oct_data["BEGIN_LON"],
           "lat": cities_oct_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_oct_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace23 = {"lon": cities_nov_data["BEGIN_LON"],
           "lat": cities_nov_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_nov_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}
trace24 = {"lon": cities_dec_data["BEGIN_LON"],
           "lat": cities_dec_data["BEGIN_LAT"],
           "name": "City",
           "text": cities_dec_data["labels"],
           "marker": {"size": 4,
                      "symbol": "star-open",
                      "color": "beige"},
           "type": "scattergeo"}


# Acknowledge all the traces as a the map data
data2 = Data([trace1, trace2, trace3, trace4,
              trace5, trace6, trace7, trace8,
              trace9, trace10, trace11, trace12,
              trace13, trace14, trace15, trace16,
              trace17, trace18, trace19, trace20,
              trace21, trace22, trace23, trace24])


# Design the layout/background
layout2 = dict(geo = dict(scope = 'north america',
                          showland = True,
                          landcolor = "rgb(0, 0, 0)",
                          subunitcolor = "rgb(255, 255, 255)",
                          countrycolor = "rgb(255, 255, 255)",
                          showlakes = True,
                          showocean = True,
                          lakecolor = "rgb(23, 23, 23)",
                          oceancolor = "rgb(23, 23, 23)",
                          showsubunits = True,
                          showcountries = True,
                          resolution = 50,
                          lonaxis = dict(showgrid = True,
                                         gridwidth = 0.05,
                                         range= [-125.0, -70.0],
                                         dtick = 5),
                          lataxis = dict(showgrid = True,
                                         gridwidth = 0.05,
                                         range= [23.0, 50.0],
                                         dtick = 5)),
               title = 'Expected Tornado Damage Values for 2018',
               showlegend = False)


# Set up the dropdown selections
updatemenus = [{'buttons': [{'args': ['visible', [True, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  True, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False]],
                             'label': 'Show January',
                             'method': 'restyle'},
                            {'args': ['visible', [False, True, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, True, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False]],
                             'label': 'Show February',
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, True, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, True, False,
                                                  False, False, False, False,
                                                  False, False, False, False]],
                             'label': "Show March",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, True,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, True,
                                                  False, False, False, False,
                                                  False, False, False, False]],
                             'label': "Show April",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  True, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  True, False, False, False,
                                                  False, False, False, False]],
                             'label': "Show May",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, True, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, True, False, False,
                                                  False, False, False, False]],
                             'label': "Show June",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, True, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, True, False,
                                                  False, False, False, False]],
                             'label': "Show July",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, False, True,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, True,
                                                  False, False, False, False]],
                             'label': "Show August",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, False, False,
                                                  True, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  True, False, False, False]],
                             'label': "Show September",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, False, False,
                                                  False, True, False, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, True, False, False]],
                             'label': "Show October",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, True, False,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, True, False]],
                             'label': "Show November",
                             'method': 'restyle'},
                            {'args': ['visible', [False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, True,
                                                  False, False, False, False,
                                                  False, False, False, False,
                                                  False, False, False, True]],
                             'label': "Show December",
                             'method': 'restyle'}],
               'type': 'buttons'}]


# Add those dropdown selections to the layout information
layout2['updatemenus'] = updatemenus


# Make the figure
fig2 = {'data':data2,
       'layout':layout2}


# Plot the figure
plotly.offline.iplot(fig2)